from vnpy.api.oes.vnoes import OesApi_GetErrorMsg, OesApi_GetLastError


def error_to_str(code: int):
    try:
        # return error_codes[code]
        return OesApi_GetErrorMsg(code)
    except KeyError:
        return "Unknown error code!"


def get_last_error():
    code = OesApi_GetLastError()
    return OesApi_GetErrorMsg(code)


error_codes = {
    1001: "报文格式错误",
    1002: "当前主机不是主节点",
    1003: "主存库操作失败",
    1004: "因状态等基础数据不匹配，无法更新数据",
    1005: "协议版本不兼容",
    1006: "数据不存在",
    1007: "未到达服务开放时间",
    1008: "非法的定位游标",
    1009: "非法的客户端登陆用户名称",
    1010: "非法的证券代码",
    1011: "非法的客户代码",
    1012: "非法的客户端类型",
    1013: "客户端已被禁用",
    1014: "客户端密码不正确",
    1015: "客户端重复登录",
    1016: "客户端连接数量过多",
    1017: "客户端未经授权操作他人账户",
    1018: "数据超出修改范围",
    1019: "非法的应用系统名称",
    1020: "请求条件有冲突",
    1021: "非法的客户端IP/MAC地址格式",
    1022: "尚不支持此业务",
    1023: "非法的客户端环境号",
    1024: "交易所拒绝",
    1025: "主柜拒绝",
    1026: "流量超出限制范围",
    1027: "禁止使用API登录",
    1028: "非法的私募基金产品代码",
    1029: "密码未改变",
    1030: "非法的来源分类",
    1031: "非法的加密类型",
    1032: "非法的客户端设备序列号",
    1033: "无可用节点",
    1101: "登录柜台失败",
    1102: "上报至柜台失败",
    1103: "从柜台获取状态失败",
    1201: "非法的证券账户代码",
    1202: "非法的资金账户代码",
    1203: "非法的出入金方向",
    1204: "非法的市场代码",
    1205: "非法的证券类别",
    1206: "非法的买卖类型",
    1207: "非法的币种",
    1208: "非法的委托类型",
    1209: "无效的账户状态",
    1210: "未找到委托信息",
    1211: "未找到持仓信息",
    1212: "未找到出入金流水",
    1213: "流水号重复",
    1214: "当前时段不能报价",
    1215: "没有操作权限",
    1216: "可用/可取资金余额不足",
    1217: "可用持仓不足",
    1218: "委托数量不在合法区间内",
    1219: "非数量单位的整数倍",
    1220: "非法的PBU代码",
    1221: "价格不在合法区间内",
    1222: "非价格单位的整数倍",
    1223: "无涨停价市价委托失败",
    1224: "当前时段不支持市价委托",
    1225: "无效的订单状态",
    1226: "撤单信息与原始委托不符",
    1227: "重复撤单",
    1228: "未通过限仓检查",
    1229: "未通过限购检查",
    1230: "超过了ETF最大现金替代比例",
    1231: "非行权日",
    1232: "产品（证券）停牌",
    1233: "合约限制开仓",
    1234: "当日累计申购或赎回数量超过限额",
    1235: "当日累计净申购或净赎回数量超过限额",
    1236: "找不到前收盘价",
    1237: "超过报撤比限制",
    1238: "委托请求过于频繁",
    1239: "非法的出入金转账金额",
    1240: "重复的认购委托",
    1241: "认购委托份数超过认购额度",
    1242: "出入金笔数超过限制",
    1243: "禁止同时做多笔出入金",
    1244: "非法的新股配号、中签记录类型",
    1245: "限制股东账户进行买交易",
    1246: "限制股东账户进行卖交易",
    1247: "限制股东账户进行逆回购交易",
    1248: "限制股东账户进行新股认购交易",
    1249: "股东账户没有市价委托交易的权限",
    1250: "股东账户没有交易创业板证券的权限",
    1251: "股东账户没有交易分级基金的权限",
    1252: "股东账户没有债券合格投资者的权限",
    1253: "客户风险评级低于交易证券需求的风险等级",
    1254: "股东账户没有交易风险警示证券的权限",
    1255: "股东账户没有交易退市整理证券的权限",
    1256: "股东账户没有交易单市场ETF的权限",
    1257: "股东账户没有交易跨市场ETF的权限",
    1258: "股东账户没有交易货币基金ETF的权限",
    1259: "股东账户没有交易跨境ETF的权限",
    1260: "仅允许合格投资者投资该证券",
    1261: "仅允许合格机构投资者投资该证券",
    1262: "出入金执行异常，待人工干预",
    1263: "交易日不在证券的发行期内",
    1264: "ETF产品禁止申购",
    1265: "ETF产品禁止赎回",
    1266: "限制股东账户进行撤指定",
    1267: "限制股东账户进行转托管",
    1268: "机构客户/主柜业务不支持银行转帐",
    1269: "不能买入被禁止开仓的证券",
    1270: "不能买入黑名单中的证券",
    1271: "股东账户没有交易存托凭证的权限",
    1272: "股东账户没有交易创新企业股票的权限",
    1273: "非法的出入金转账类型",

}
